﻿<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:LightningTools_BCSTesterMan="clr-namespace:LightningTools.BCSTesterMan" xmlns:ViewModel="clr-namespace:LightningTools.BCSTesterMan.ViewModel;assembly=LightningTools.BCSTesterMan.ViewModel" x:Class="LightningTools.BCSTesterMan.View.BcsView" mc:Ignorable="d" d:DesignHeight="408" d:DesignWidth="351">

	<UserControl.Resources>
		<Style x:Key="IsLoadingEntitiesStyle" TargetType="{x:Type LightningTools_BCSTesterMan:ucWaitingSpinner}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding IsLoadingEntities, UpdateSourceTrigger=PropertyChanged}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>
		
		<Style x:Key="IsLoadingMethodParametersStyle" TargetType="{x:Type LightningTools_BCSTesterMan:ucWaitingSpinner}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding ActiveMethod.IsLoading, UpdateSourceTrigger=PropertyChanged}" Value="false">
					<Setter Property="Visibility" Value="Collapsed" />
				</DataTrigger>
			</Style.Triggers>
		</Style>
	</UserControl.Resources>

	<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
		<StackPanel d:DataContext="{d:DesignInstance {x:Type ViewModel:MainWindowViewModel}}">
			<Label Content="SharePoint URL" Width="351" />
			<Grid Height="21.96" Width="335">
				<TextBox x:Name="SharePointUrlTextBox" Text="{Binding Url, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Margin="0,0,52,0" d:LayoutOverrides="Height" />
				<Button Command="{Binding LoadEctCommand}" IsDefault="True" Margin="287,0,0,0" d:LayoutOverrides="VerticalAlignment">
					<StackPanel Orientation="Horizontal">
						<TextBlock Text="&gt;&gt;" />
						<LightningTools_BCSTesterMan:ucWaitingSpinner Style="{StaticResource IsLoadingEntitiesStyle}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="15" Height="15" />
					</StackPanel>
				</Button>

			</Grid>

			<TreeView x:Name="EntityTreeView" BorderThickness="0px" Tag="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TreeViewItem.Selected="OnItemSelected" ItemsSource="{Binding ExternalContentTypes, UpdateSourceTrigger=PropertyChanged}" Margin="8" Background="{x:Null}" Foreground="{x:Null}">
				<TreeView.Resources>

					<HierarchicalDataTemplate DataType="{x:Type ViewModel:EntityViewModel}" ItemsSource="{Binding Children}">
						<StackPanel Orientation="Horizontal">
							<Image Width="16" Height="16" Source="../Images/logo.png" />
							<TextBlock Text="{Binding Name}">
								<TextBlock.ToolTip>
									<StackPanel>
										<TextBlock Text="{Binding Namespace, StringFormat=Namespace: \{0\}}" />
										<TextBlock Text="{Binding Version, StringFormat=Version: \{0\}}" />
									</StackPanel>
								</TextBlock.ToolTip>
							</TextBlock>
						</StackPanel>
					</HierarchicalDataTemplate>

					<DataTemplate DataType="{x:Type ViewModel:MethodViewModel}">

						<StackPanel Orientation="Horizontal" x:Name="stck">
							<StackPanel.ContextMenu>
								<ContextMenu>
									<MenuItem Command="Cut">
										<MenuItem.Icon>
											<Image Source="../Images/go.jpg" />
										</MenuItem.Icon>
									</MenuItem>
								</ContextMenu>
							</StackPanel.ContextMenu>
							<!--<LightningTools_BCSTesterMan:ucWaitingSpinner Style="{StaticResource IsLoadingMethodParametersStyle}" VerticalAlignment="Top" HorizontalAlignment="Left" Width="16" Height="16" />-->
							<Image Width="16" Height="16" Source="../Images/method.gif" />
							<TextBlock x:Name="txt" Text="{Binding Name}" />
						</StackPanel>

						<DataTemplate.Triggers>
							<DataTrigger Binding="{Binding IsSupported}" Value="false">
								<Setter TargetName="txt" Property="Foreground" Value="LightGray" />
							</DataTrigger>
						</DataTemplate.Triggers>

					</DataTemplate>

				</TreeView.Resources>

				<TreeView.ItemContainerStyle>
					<Style TargetType="{x:Type TreeViewItem}">
						<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
						<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
						<Setter Property="FontWeight" Value="Normal" />
						<Style.Triggers>
							<Trigger Property="IsSelected" Value="True">
								<Setter Property="FontWeight" Value="Bold" />
							</Trigger>
						</Style.Triggers>
					</Style>
				</TreeView.ItemContainerStyle>

			</TreeView>

		</StackPanel>
	</ScrollViewer>
</UserControl>